package com.woniuxy.rms.controller;

import com.woniuxy.rms.pojo.Admins;
import com.woniuxy.rms.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Auther: ChenGang  <br/>
 * Date: 2020/4/2 0002:上午 11:02  <br/>
 * Description:后台首页
 */
@Controller
@RequestMapping("/system")
public class IndexController {

    @Autowired
    UserService userService;

    /**
     * Description : 后台管理首页  <br/>
     * ChangeLog : 1. 创建 (2020/4/2 0002 上午 11:05 [Administrator]);
     * @param model
     * @return org.springframework.web.servlet.ModelAndView
    */
    @GetMapping("/index")
    public ModelAndView index(ModelAndView model){
        //获取登录信息
        Admins admin = (Admins) SecurityUtils.getSubject().getPrincipal();
        model.addObject("admin",admin);
        model.setViewName("system/index");
        return model;
    }
    /**
     * Description : 统计页  <br/>
     * ChangeLog : 1. 创建 (2020/4/2 0002 上午 11:12 [Administrator]);
     * @param model
     * @return org.springframework.web.servlet.ModelAndView
    */
    @GetMapping("/main")
    public ModelAndView main(ModelAndView model){
        model.setViewName("system/main");
        //查询今天的用户条数
        Integer toDay = userService.findByToDay();
        //查询昨天的用户条数
        Integer yesterday = userService.findByYesterday();
        //查询本周用户条数
        Integer tWeek = userService.findByWeek();
        //查询本月用户条数
        Integer tMonth = userService.findByMonth();
        //查询所有 用户条数
        Long all = userService.findAllCount();
        model.addObject("usersToday",toDay);
        model.addObject("userTotal",all);
        model.addObject("usersYestoday",yesterday);
        model.addObject("usersYearWeek",tWeek);
        model.addObject("usersMonth",tMonth);
        return model;
    }

}